<section id="main-content">
	<section class="wrapper">
		<!--state overview start-->
		<div class="row">
			<div class="col-lg-12">
				<!-- 数据概览 -->
				<div class="row">
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								搜索条件
							</header>
							<div class="panel-body" style="padding-bottom: 0;">
								<div class="row">
									<div class="col-lg-6">
										<div class="input-group m-bot15">
											<span class="input-group-addon" style="position: relative;z-index: 2;">年份</span>
											<select class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;"
												id="searchYear">
												<option value="2018">2018年</option>
												<option value="2019">2019年</option>
												<option value="2020">2020年</option>
												<option value="2021">2021年</option>
												<option value="2022">2022年</option>
												<option value="2023">2023年</option>
												<option value="2024">2024年</option>
												<option value="2025">2025年</option>
												<option value="2026">2026年</option>
												<option value="2027">2027年</option>
												<option value="2028">2028年</option>
											</select>
										</div>
									</div>
									<div class="col-lg-6">
										<div class="input-group m-bot15">
											<span class="input-group-addon" style="position: relative;z-index: 2;">公司</span>
											<select class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;"
												id="company" ng-model="company">
												<option value="" selected>全部公司</option>
												<option ng-repeat="x in comp" value="{{x.companyId}}">{{x.company}}</option>
											</select>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-lg-6">
										<div class="input-group m-bot15">
											<span class="input-group-addon" style="position: relative;z-index: 2;">类型</span>
											<select class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;"
												id="proType" ng-model="ngChange" ng-change="search2()">
												<option value="">全部</option>
												<option value="ZL">战略类</option>
												<option value="YF">研发类</option>
												<option value="XS">销售类</option>
												<option value="BM">部门类</option>
												<option value="SW">事务类</option>
												<option value="CS">测试类</option>
											</select>
										</div>
									</div>
									<div class="col-lg-6">
										<button class="btn btn-info searchs" style="margin-bottom:15px;">搜索</button>
									</div>
								</div>
							</div>
						</section>
						<section class="panel">
							<header class="panel-heading">
								当前运行中的项目
							</header>
							<div class="panel-body">
								<ul class="summary-list">
									<li>
										<a href="javascript:;">
											<i class="text-success">销售类项目</i>
											{{xsCount}}
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<i class="text-danger">研发类项目</i>
											{{yfCount}}
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<i class="text-info">战略类项目</i>
											{{zlCount}}
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<i class="text-muted">部门类项目</i>
											{{bmCount}}
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<i class="text-primary">事务类项目</i>
											{{swCount}}
										</a>
									</li>
								</ul>
							</div>
						</section>
						<section class="panel">
							<header class="panel-heading">
								收入回款情况
							</header>
							<div class="weather-category">
								<ul>
									<li>
										<h5>当前阶段收入</h5>
										￥{{kpandhkmoney}}元
									</li>
									<li>
										<h5>已开票总额</h5>
										￥{{kptotalMoney}}元
									</li>
									<li>
										<h5>已回款总额</h5>
										￥{{hktotalMoney}}元
									</li>
								</ul>
							</div>
						</section>
					</div>

					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								项目开票和回款按月分布
								<i class="add-icon">实时刷新</i>
							</header>
							<div class="panel-body">
								<div id="main8" style="width:100%;height:369px;"></div>
							</div>
						</section>
					</div>
				</div>

				<div class="row">
					<div class="col-lg-12">
						<section class="panel">
							<header class="panel-heading">
								总成本：￥<span id="proMoney"></span>元
								<div class="pull-right hed-msg">
									<i class="icon-tag"> 此处项目总成本统计未包括商用采购费用和产品研发成本</i>
								</div>
							</header>
							<div class="panel-body">
								<ul class="ft-link">
									<li>
										<a href="javascript:;">
											<h5>人力总成本</h5>
											￥{{totalMoney}}元
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<h5>非商用采购费</h5>
											￥{{cgtotalMoney2}}元
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<h5>出差报销总费</h5>
											￥{{bxtotalMoney}}元
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<h5>折旧总费</h5>
											￥{{totalzjMoney}}元
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<h5>现金报销总费</h5>
											￥0元
										</a>
									</li>
									<li>
										<a href="javascript:;">
											<h5>招待报销总费</h5>
											￥0元
										</a>
									</li>
									<li>
										<a href="javascript:;" class="text-danger">
											<h5>商用采购费</h5>
											￥{{cgsymoney2}}元
										</a>
									</li>
								</ul>
							</div>
						</section>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								项目人力投入和人力费用按月分布
								<i class="add-icon">更新于昨晚24点</i>
							</header>
							<div class="panel-body">
								<div id="main2" style="width:100%;height:400px;"></div>
							</div>
						</section>
					</div>
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								项目出差总费用（预测和实际）按月分布
								<span class="label label-danger pull-right">出差总费用：{{totalBuss}}元</span>
							</header>
							<div class="panel-body">
								<div id="main4" style="width:100%;height:400px;"></div>
							</div>
						</section>

					</div>
				</div>
				<section class="panel">
					<header class="panel-heading">
						项目出差类型报销总费用按月分布
						<i class="add-icon">实时刷新</i>
					</header>
					<div class="panel-body">
						<div id="main6" style="width:100%;height:400px;"></div>
					</div>
				</section>

				<section class="panel">
					<header class="panel-heading">
						项目采购预测和实际费用按月分布
						<span class="label label-success pull-right ">实际非商用采购总费用：￥{{cgtotalMoney2}}元</span>
						<span class="label label-info pull-right mr-5">实际商用采购总费用：￥{{cgsymoney2}}元</span>
					</header>
					<div class="panel-body">
						<div id="main10" style="width:100%;height:400px;"></div>
					</div>
				</section>

				<div class="row">
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								资产折旧费用按月分布
								<i class="add-icon">实时刷新</i>
							</header>
							<div class="panel-body">
								<div id="main7" style="width:100%;height:400px;"></div>
							</div>
						</section>
					</div>
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								项目预估收入按阶段分布
								<i class="add-icon">实时刷新</i>
							</header>
							<div class="panel-body">
								<div id="main9" style="width:100%;height:400px;"></div>
							</div>
						</section>
					</div>
				</div>








				<div class="row">
					<div class="col-lg-6">

						<section class="panel">
							<header class="panel-heading">
								项目人力投入和人力费用按项目阶段分布
								<i class="add-icon">实时刷新</i>
							</header>
							<div class="panel-body">
								<div id="main1" style="width:100%;height:400px;"></div>
							</div>
						</section>
					</div>
					<div class="col-lg-6">
						<section class="panel">
							<header class="panel-heading">
								项目出差总费用（预测和实际）按项目阶段分布
								<i class="add-icon">更新于昨晚24点</i>
							</header>
							<div class="panel-body">
								<div id="main5" style="width:100%;height:400px;"></div>
							</div>
						</section>

					</div>
				</div>


			</div>
		</div>
		<!--state overview end-->
	</section>
</section>
<!-- echarts组件 -->
<script type="text/javascript" src="assets/echarts/echarts.min.js"></script>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<script>
	function findProData($scope, CertusFormAjax, $q) {
		var date = new Date;
		var year = date.getFullYear();
		$("#searchYear").val(year);
		CertusFormAjax.ajax("isCrcd", {
			"code": "GSTB"
		}, function (response) {
			var data = JSON.parse(response.data);
			if (data.comanyCode != "") {
				CertusFormAjax.ajax("companyListByCode", { "code": data.comanyCode }, function (response) {
					$scope.comp = JSON.parse(response.data);
				});
			}
		});

		$(".searchs").on('click', function () {
			search2();
		});

		this.search2 = function () {
			var proType = $("#proType").val();
			var year = $("#searchYear").val();
			var companyCode = $("#company").val();
			monthTjs(proType, year, companyCode);
			bussesPhasTjs(proType, year, companyCode);
			bugetTjs(proType, year, companyCode);
			proCounts(proType);

            phaseTjs(proType, year, companyCode);
            bussesMTjs(proType, year, companyCode);
            bussesType(proType, year, companyCode);
            assetMs(proType, year, companyCode);
            cgTjs(proType, year, companyCode);
            kpAndHkTjs(proType, year, companyCode);

            setTimeout(function () {
                var proMoney = $scope.totalMoney +
                    $scope.cgMoney + $scope.bxtotalMoney +
                    $scope.totalzjMoney;
                $("#proMoney").html(proMoney);
            },500)
			// $q.all([
			// 	phaseTjs(proType, year, companyCode),
			// 	bussesMTjs(proType, year, companyCode),
			// 	bussesType(proType, year, companyCode),
			// 	assetMs(proType, year, companyCode),
			// 	cgTjs(proType, year, companyCode),
			// 	kpAndHkTjs(proType, year, companyCode)
			// ])
			// 	.then(function (result) {
			// 		// console.log(result);
			// 		// console.log(result[3].totalMoney);
			// 		// console.log(result[3].cgMoney);
			// 		// console.log(result[3].bxtotalMoney);
			// 		// console.log(result[3].totalzjMoney);
            //
             //        $scope.proMoney = result[3].totalMoney +
             //            result[3].cgMoney + result[3].bxtotalMoney +
             //            result[3].totalzjMoney;
			// 	});
		};
		this.proCounts = function () {
			CertusFormAjax.ajax('findProTypeCounts', { "company": $("#company").val() }, function (response) {
				var data = response.data;
				for (var i = 0; i < data.length; i++) {
					if (data[i].proType == "XS") {
						$scope.xsCount = data[i].count;
					} else if (data[i].proType == "ZL") {
						$scope.zlCount = data[i].count;
					} else if (data[i].proType == "YF") {
						$scope.yfCount = data[i].count;
					} else if (data[i].proType == "BM") {
						$scope.bmCount = data[i].count;
					} else {
						$scope.swCount = data[i].count;
					}
				}
			});
		};

		this.phaseTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findPhaseTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var totalRt = 0;
				var totalMoney = 0;
				var yccost = [];
				var sjcost = [];
				var ycrt = [];
				var sjrt = [];

				for (var i = 0; i < data.length; i++) {
					totalRt += data[i].actualday;
					totalMoney += data[i].actualcost;
					if (data[i].phase == "XS") {
						yccost[0] = data[i].forecastcost;
						sjcost[0] = data[i].actualcost;
						ycrt[0] = data[i].forecastday;
						sjrt[0] = data[i].actualday;
					} else if (data[i].phase == "LX") {
						yccost[1] = data[i].forecastcost;
						sjcost[1] = data[i].actualcost;
						ycrt[1] = data[i].forecastday;
						sjrt[1] = data[i].actualday;
					} else if (data[i].phase == "TB") {
						yccost[2] = data[i].forecastcost;
						sjcost[2] = data[i].actualcost;
						ycrt[2] = data[i].forecastday;
						sjrt[2] = data[i].actualday;
					} else if (data[i].phase == "JF") {
						yccost[3] = data[i].forecastcost;
						sjcost[3] = data[i].actualcost;
						ycrt[3] = data[i].forecastday;
						sjrt[3] = data[i].actualday;
					} else {
						yccost[4] = data[i].forecastcost;
						sjcost[4] = data[i].actualcost;
						ycrt[4] = data[i].forecastday;
						sjrt[4] = data[i].actualday;
					}
				}
				$scope.totalRt = totalRt;
				$scope.totalMoney = totalMoney;
				var myChart1 = echarts.init(document.getElementById('main1'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross',
							crossStyle: {
								color: '#999'
							}
						}
					},
					toolbox: {
						feature: {
							dataView: {
								show: true,
								readOnly: true,
								optionToContent: function (opt) {
									//console.info(opt);
									var axisData = opt.xAxis[0].data;
									var series = opt.series;
									var tdHeaders = '<td>阶段</td>'; //表头
									series.forEach(function (item) {
										tdHeaders += '<td>' + item.name + '</td>'; //组装表头
									});
									var table = '<div class="table-responsive"><table class="table table-bordered table-striped table-hover" style="text-align:center"><tbody><tr>' + tdHeaders + '</tr>';
									var tdBodys = ''; //数据
									for (let i = 0, l = axisData.length; i < l; i++) {
										for (let j = 0; j < series.length; j++) {
											tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据
										}
										table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>';
										tdBodys = '';
									}

									table += '</tbody></table></div>';
									return table;
								}
							},
							magicType: {
								show: true,
								type: ['line', 'bar']
							},
							restore: {
								show: true
							},
							saveAsImage: {
								show: false
							}
						}
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '5%',
						containLabel: true
					},
					legend: {
						data: ['预测成本', '实际成本', '预测人天', '实际人天'],
						left: 50
					},
					xAxis: [{
						type: 'category',
						data: ['线索', '运作', '合同', '交付', '回款'],
						axisPointer: {
							type: 'shadow'
						}
					}],
					yAxis: [{
						type: 'value',
						name: '元',
						axisLabel: {
							formatter: '￥{value}'
						}
					},
					{
						type: 'value',
						name: '人/天',
						axisLabel: {
							formatter: '{value}'
						}
					}
					],
					series: [{
						name: '预测成本',
						type: 'bar',
						data: yccost,
						barWidth: '20%',
						itemStyle: {
							normal: {
								color: '#4a8bc2'
							}
						},
					},
					{
						name: '实际成本',
						type: 'bar',
						data: sjcost,
						barWidth: '20%',
						itemStyle: {
							normal: {
								color: '#a9d86e'
							}
						},
					},
					{
						name: '预测人天',
						type: 'line',
						yAxisIndex: 1,
						barWidth: '20%',
						data: ycrt,
						itemStyle: {
							normal: {
								color: '#009999'
							}
						},
					},
					{
						name: '实际人天',
						type: 'line',
						yAxisIndex: 1,
						barWidth: '20%',
						data: sjrt,
						itemStyle: {
							normal: {
								color: '#FFCC33'
							}
						},
					}
					]
				};
				myChart1.setOption(option);
				return $scope.totalRt;
			});
		};
		this.monthTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findMonthTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var yccost = [];
				var sjcost = [];
				var ycrt = [];
				var sjrt = [];
				for (var i = 0; i < data.length; i++) {
					yccost[i] = data[i].yccost;
					sjcost[i] = data[i].sjcost;
					ycrt[i] = data[i].ycpercent / 100;
					sjrt[i] = data[i].sjpercent / 100;
				}
				var myChart2 = echarts.init(document.getElementById('main2'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross',
							crossStyle: {
								color: '#999'
							}
						}
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '5%',
						containLabel: true
					},
					toolbox: {
						feature: {
							dataView: {
								show: true,
								readOnly: true,
								optionToContent: function (opt) {
									//console.info(opt);
									var axisData = opt.xAxis[0].data;
									var series = opt.series;
									var tdHeaders = '<td>时间</td>'; //表头
									series.forEach(function (item) {
										tdHeaders += '<td>' + item.name + '</td>'; //组装表头
									});
									var table = '<div class="table-responsive"><table class="table table-bordered table-striped table-hover" style="text-align:center"><tbody><tr>' + tdHeaders + '</tr>';
									var tdBodys = ''; //数据
									for (let i = 0, l = axisData.length; i < l; i++) {
										for (let j = 0; j < series.length; j++) {
											tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据
										}
										table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>';
										tdBodys = '';
									}

									table += '</tbody></table></div>';
									return table;
								}
							},
							magicType: {
								show: true,
								type: ['line', 'bar']
							},
							restore: {
								show: true
							},
							saveAsImage: {
								show: false
							}
						}
					},
					legend: {
						data: ['预测成本', '实际成本', '预测人天', '实际人天'],
						left: 50
					},
					xAxis: [{
						type: 'category',
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
							'11月', '12月'
						],
						axisPointer: {
							type: 'shadow'
						}
					}],
					yAxis: [{
						type: 'value',
						name: '元',
						axisLabel: {
							formatter: '￥{value}'
						}
					},
					{
						type: 'value',
						name: '人/天',
						axisLabel: {
							formatter: '{value}'
						}
					}
					],
					series: [{
						name: '预测成本',
						type: 'bar',
						data: yccost,
						borWidth: '20%',
						itemStyle: {
							normal: {
								color: '#4a8bc2'
							}
						},
					},
					{
						name: '实际成本',
						type: 'bar',
						data: sjcost,
						borWidth: '20%',
						itemStyle: {
							normal: {
								color: '#a9d86e'
							}
						},
					},
					{
						name: '预测人天',
						type: 'line',
						yAxisIndex: 1,
						data: ycrt,
						borWidth: '20%',
						itemStyle: {
							normal: {
								color: '#009999'
							}
						},
					},
					{
						name: '实际人天',
						type: 'line',
						yAxisIndex: 1,
						data: sjrt,
						borWidth: '20%',
						itemStyle: {
							normal: {
								color: '#FFCC33'
							}
						},
					}
					]
				};
				myChart2.setOption(option);
			});
		};


		this.bussesMTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findBussesTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var bugetlist = data.nbugetList;
				var treimlist = data.ntreimList;
				var yccost = [];
				var sjcost = [];
				var totalBussMoney = 0;
				for (var i = 0; i < bugetlist.length; i++) {
					yccost[i] = bugetlist[i].ycbuget;
				}
				for (var i = 0; i < treimlist.length; i++) {
					sjcost[i] = treimlist[i].totalMoney;
					totalBussMoney += treimlist[i].totalMoney;
				}
				$scope.totalBuss = totalBussMoney;
				var myChart2 = echarts.init(document.getElementById('main4'));
				option = {
					tooltip: {
						trigger: 'axis'
					},
					legend: {
						data: ['预测费用', '实际费用']
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月',
							'12月'
						]
					},
					yAxis: {
						type: 'value'
					},
					series: [{
						name: '预测费用',
						type: 'line',
						data: yccost,
						itemStyle: {
							normal: {
								color: '#009999'
							}
						},
					},
					{
						name: '实际费用',
						type: 'line',
						data: sjcost,
						itemStyle: {
							normal: {
								color: '#FFCC33'
							}
						},
					}
					]
				};
				myChart2.setOption(option);
			});
			return $scope;
		};

		this.bussesPhasTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findBussesPhasTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var bugetlist = data.bugetList;
				var treimDays = data.treimDays;
				var yccost = [];
				var sjcost = [];
				for (var i = 0; i < bugetlist.length; i++) {
					yccost[i] = bugetlist[i].buget;
				}
				for (var i = 0; i < treimDays.length; i++) {
					if (treimDays[i].phase == "XS") {
						sjcost.push(treimDays[i].cost);
					} else if (treimDays[i].phase == "LX") {
						sjcost.push(treimDays[i].cost);
					} else if (treimDays[i].phase == "TB") {
						sjcost.push(treimDays[i].cost);
					} else if (treimDays[i].phase == "JF") {
						sjcost.push(treimDays[i].cost);
					} else {
						sjcost.push(treimDays[i].cost);
					}
				}
				var myChart2 = echarts.init(document.getElementById('main5'));
				option = {
					tooltip: {
						trigger: 'axis'
					},
					legend: {
						data: ['预测费用', '实际费用']
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '5%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: ["线索", "运作", "合同", "交付", "回款"]
					},
					yAxis: {
						type: 'value'
					},
					series: [{
						name: '预测费用',
						type: 'line',
						data: yccost
					},
					{
						name: '实际费用',
						type: 'line',
						data: sjcost
					}
					]
				};

				myChart2.setOption(option);
			});
		}

		this.bussesType = function (param, year, compCode) {
			CertusFormAjax.ajax('findMBusessTypeByPro', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var bxtotalMoney = 0;
				var trains = [];
				var plans = [];
				var traffics = [];
				var hotels = [];
				var repetitions = [];
				var others = [];
				var travelAllowances = [];
				var fmonth = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
				for (var i = 0; i < data.length; i++) {
					var code = data[i].tri_class_code;
					var emonth = data[i].month;
					var name = data[i].totalMoney;
					bxtotalMoney += data[i].totalMoney;
					if (code == "train") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								trains.push(name);
							}
						}
					} else if (code == "plan") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								plans.push(name);
							}
						}
					} else if (code == "traffic") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								traffics.push(name);
							}
						}
					} else if (code == "hotel") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								hotels.push(name);
							}
						}
					} else if (code == "repetition") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								repetitions.push(name);
							}
						}
					} else if (code == "others") {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								others.push(name);
							}
						}
					} else {
						for (var j = 0; j < fmonth.length; j++) {
							if (emonth == fmonth[j]) {
								travelAllowances.push(name);
							}
						}
					}
				}
				$scope.bxtotalMoney = bxtotalMoney;
				var myChart2 = echarts.init(document.getElementById('main6'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: { // 坐标轴指示器，坐标轴触发有效
							type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
						}
					},
					legend: {
						data: ['火车/汽车', '飞机', '交通费用', '住宿费用', '招待费', '其他费用', '出差补助'],
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
							'11月', '12月'
						]
					}],
					yAxis: [{
						type: 'value'
					}],
					series: [{
						name: '火车/汽车',
						type: 'bar',
						barWidth: 20,
						stack: '各类出差报销',
						data: trains,
						itemStyle: {
							normal: {
								color: '#5475f5'
							}
						},
					},
					{
						name: '飞机',
						type: 'bar',
						stack: '各类出差报销',
						data: plans,
						itemStyle: {
							normal: {
								color: '#9feaa5'
							}
						},
					},
					{
						name: '交通费用',
						type: 'bar',
						stack: '各类出差报销',
						data: traffics,
						itemStyle: {
							normal: {
								color: '#85daef'
							}
						},
					},
					{
						name: '住宿费用',
						type: 'bar',
						stack: '各类出差报销',
						data: hotels,
						itemStyle: {
							normal: {
								color: '#74e2ca'
							}
						},
					},
					{
						name: '招待费',
						type: 'bar',
						stack: '各类出差报销',
						data: repetitions,
						itemStyle: {
							normal: {
								color: '#e6ac53'
							}
						},
					},
					{
						name: '其他费用',
						type: 'bar',
						stack: '各类出差报销',
						data: others,
						itemStyle: {
							normal: {
								color: '#ff6c60'
							}
						},
					},
					{
						name: '出差补助',
						type: 'bar',
						stack: '各类出差报销',
						data: travelAllowances,
						itemStyle: {
							normal: {
								color: '#a9d86e'
							}
						},
					}
					]
				};
				myChart2.setOption(option);
				return $scope;
			});
		}

		this.assetMs = function (param, year, compCode) {
			CertusFormAjax.ajax('findAssetMs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var moneys = [];
				var totalMoney = 0;
				for (var i = 0; i < data.length; i++) {
					moneys.push(data[i].totalMoney);
					totalMoney += data[i].totalMoney;
				}
				$scope.totalzjMoney = totalMoney;
				var myChart2 = echarts.init(document.getElementById('main7'));
				option = {
					color: ['#3398DB'],
					tooltip: {
						trigger: 'axis',
						axisPointer: { // 坐标轴指示器，坐标轴触发有效
							type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
						}
					},
					legend: {
						data: ['资产折旧费用']
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
							'11月', '12月'
						],
						axisTick: {
							alignWithLabel: true
						}
					}],
					yAxis: [{
						type: 'value'
					}],
					series: [{
						name: '资产折旧费用',
						type: 'bar',
						barWidth: '60%',
						data: moneys
					}]
				};
				myChart2.setOption(option);
			})
			return $scope;
		};
		//开票和回款按月统计
		this.kpAndHkTjs = function (param, year, compCode) {
			return CertusFormAjax.ajax('findPayTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var payList = response.data.payList;
				var invoiceList = response.data.invoiceList;
				var kpbuget = [];
				var hkbuget = [];
				var kptotalMoney = 0;
				var hktotalMoney = 0;
				for (var i = 0; i < invoiceList.length; i++) {
					kpbuget.push(invoiceList[i].buget);
					hktotalMoney += invoiceList[i].buget;
				}
				for (var i = 0; i < payList.length; i++) {
					hkbuget.push(payList[i].buget);
					kptotalMoney += payList[i].buget;
				}
				$scope.kpandhkmoney = kptotalMoney + hktotalMoney;
				$scope.kptotalMoney = kptotalMoney;
				$scope.hktotalMoney = hktotalMoney;

				var myChart2 = echarts.init(document.getElementById('main8'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross',
							crossStyle: {
								color: '#999'
							}
						}
					},
					toolbox: {
						feature: {
							dataView: {
								show: true,
								readOnly: true,
								optionToContent: function (opt) {
									//console.info(opt);
									var axisData = opt.xAxis[0].data;
									var series = opt.series;
									var tdHeaders = '<td>时间</td>'; //表头
									series.forEach(function (item) {
										tdHeaders += '<td>' + item.name + '</td>'; //组装表头
									});
									var table = '<div class="table-responsive"><table class="table table-bordered table-striped table-hover" style="text-align:center"><tbody><tr>' + tdHeaders + '</tr>';
									var tdBodys = ''; //数据
									for (let i = 0, l = axisData.length; i < l; i++) {
										for (let j = 0; j < series.length; j++) {
											tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据
										}
										table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>';
										tdBodys = '';
									}

									table += '</tbody></table></div>';
									return table;
								}
							},
							magicType: {
								show: true,
								type: ['line', 'bar']
							},
							restore: {
								show: true
							},
							saveAsImage: {
								show: false
							}
						}
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '5%',
						containLabel: true
					},
					legend: {
						data: ['开票费用', '回款费用']
					},
					xAxis: [{
						type: 'category',
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
							'11月', '12月'
						],
						axisPointer: {
							type: 'shadow'
						}
					}],
					yAxis: [{
						type: 'value',
						name: '元',
						axisLabel: {
							formatter: '￥{value}'
						}
					}],
					series: [{
						name: '开票费用',
						type: 'bar',
						data: kpbuget,
						itemStyle: {
							normal: {
								color: '#4e616d'
							}
						},
					},
					{
						name: '回款费用',
						type: 'bar',
						data: hkbuget,
						itemStyle: {
							normal: {
								color: '#ff6666'
							}
						},
					}
					]
				};
				myChart2.setOption(option);
			});
			return $scope;
		};

		//项目采购按月分布
		this.cgTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findCgTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var yctjs = data.cgycs;
				var sjtjs = data.cgsjs;
				var ycsys = [];
				var yczys = [];
				var ycwls = [];
				var sjsys = [];
				var sjzys = [];
				var sjwls = [];
				var cgtotalMoney = 0;
				var cgsymoney = 0;
				for (var i = 0; i < yctjs.length; i++) {
					if (yctjs[i].code == "SY") {
						ycsys.push(yctjs[i].totalMoney);
					} else if (yctjs[i].code == "ZY") {
						yczys.push(yctjs[i].totalMoney);
					} else {
						ycwls.push(yctjs[i].totalMoney);
					}
				}
				for (var i = 0; i < sjtjs.length; i++) {
					if (sjtjs[i].code == "SY") {
						cgsymoney += Number(yctjs[i].totalMoney);
						sjsys.push(yctjs[i].totalMoney);
					} else if (sjtjs[i].code == "ZY") {
						cgtotalMoney += Number(yctjs[i].totalMoney);
						sjzys.push(yctjs[i].totalMoney);
					} else {
						cgtotalMoney += Number(yctjs[i].totalMoney);
						sjwls.push(yctjs[i].totalMoney);
					}
				}
				$scope.cgtotalMoney2 = cgtotalMoney;
				$scope.cgsymoney2 = cgsymoney;
				var cgMoney = cgtotalMoney + cgsymoney;
				$scope.cgMoney = cgMoney;
				var myChart2 = echarts.init(document.getElementById('main10'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: { // 坐标轴指示器，坐标轴触发有效
							type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
						}
					},
					legend: {
						data: ['预测商用', '预测自用', '预测外联', '实际商用', '实际自用', '实际外联']
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
							'11月', '12月'
						]
					}],
					yAxis: [{
						type: 'value'
					}],
					series: [{
						name: '预测商用',
						type: 'bar',
						stack: '预测采购费用',
						data: ycsys
					},
					{
						name: '实际商用',
						type: 'bar',
						stack: '实际采购费用',
						data: sjsys
					},
					{
						name: '预测自用',
						type: 'bar',
						stack: '预测采购费用',
						data: yczys
					},
					{
						name: '实际自用',
						type: 'bar',
						stack: '实际采购费用',
						data: sjzys
					},
					{
						name: '预测外联',
						type: 'bar',
						stack: '预测采购费用',
						data: ycwls
					},
					{
						name: '实际外联',
						type: 'bar',
						stack: '实际采购费用',
						data: sjwls
					}
					]
				};
				myChart2.setOption(option);
				return $scope;
			});
		};

		//按阶段统计预估费用
		this.bugetTjs = function (param, year, compCode) {
			CertusFormAjax.ajax('findBugetTjs', {
				"param": param, "year": year, "compCode": compCode
			}, function (response) {
				var data = response.data;
				var bugets = data.bugets;
				var yccost = [];
				for (var i = 0; i < bugets.length; i++) {
					if (bugets[i].phase_code == "XS") {
						yccost.push(bugets[0].buget);
					} else {
						yccost.push(bugets[1].buget);
					}
				}
				var tbs = data.tbs;
				yccost[2] = tbs.totalMoney;
				var hks = data.hts;
				yccost[3] = hks.totalMoney;
				var myChart2 = echarts.init(document.getElementById('main9'));
				option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross',
							crossStyle: {
								color: '#999'
							}
						}
					},
					toolbox: {
						feature: {
							dataView: {
								show: true,
								readOnly: true,
								optionToContent: function (opt) {
									var axisData = opt.xAxis[0].data;
									var series = opt.series;
									var tdHeaders = '<td>阶段</td>'; //表头
									series.forEach(function (item) {
										tdHeaders += '<td>' + item.name + '</td>'; //组装表头
									});
									var table = '<div class="table-responsive"><table class="table table-bordered table-striped table-hover" style="text-align:center"><tbody><tr>' + tdHeaders + '</tr>';
									var tdBodys = ''; //数据
									for (let i = 0, l = axisData.length; i < l; i++) {
										for (let j = 0; j < series.length; j++) {
											tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据
										}
										table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>';
										tdBodys = '';
									}

									table += '</tbody></table></div>';
									return table;

								}
							},
							magicType: {
								show: true,
								type: ['line', 'bar']
							},
							restore: {
								show: true
							},
							saveAsImage: {
								show: false
							}
						}
					},
					grid: {
						left: '3%',
						bottom: '3%',
						containLabel: true
					},
					legend: {
						data: ['项目阶段预估收入']
					},
					xAxis: [{
						type: 'category',
						data: ['线索', '运作', '合同', '交付'],
						axisPointer: {
							type: 'shadow'
						}
					}],
					yAxis: [{
						type: 'value',
						name: '元',
						axisLabel: {
							formatter: '￥{value}'
						}
					}],
					series: [{
						name: '项目阶段预估收入',
						type: 'bar',
						barWidth: '20px',
						data: yccost,
						itemStyle: {
							normal: {
								color: '#8cb8be'
							}
						},
					}]
				};
				myChart2.setOption(option);
			});
		};
		search2();
	}
</script>